import libtcodpy as libtcod

class NameGen(object):
	def __init__(self, seed):
		
		self.generator = libtcod.random_new_from_seed(seed)
		
		self.names = {}
		self.names["male"] = self.parse_names("male")
		self.names["female"] = self.parse_names("female")
		
		self.surnames = self.parse_surnames()
		pass
		
	def parse_names(self, sex = "male"):
		filename = "./data/"+sex+".txt"
		lines = open(filename, 'r').readlines()
		base = []
		for line in lines:
			base.append(line.split()[0])
			
		return base
		
	def parse_surnames(self):
		filename = "./data/surnames.csv"
		lines = open(filename, 'r').readlines()
		base = []
		for line in lines:
			base.append(line.replace('"','').split(",")[0])
			
		return base
		
	def generate(self, sex = "male"):		
		base = self.names[sex]
		base2 = self.surnames
		
		line = libtcod.random_get_int(self.generator, 0, len(base)-1)
		name = base[line]
		
		surname = base2[libtcod.random_get_int(self.generator, 0, len(base2)-1)]
		
		return name + " " + surname

#~ gen = NameGen()
#~ print gen.generate("male")
#~ print gen.generate("female")
